package com.example.service.webhook.business.chsi.repository;

import javax.annotation.Resource;

import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.example.service.webhook.business.chsi.entity.EducationInfoEntity;
import com.example.service.webhook.repository.base.BaseDAO;
import com.example.service.webhook.util.DateUtil;
/**
 * 学信网 学籍信息
 * ClassName: EducationRepository    
 * date: 2016年7月26日 下午5:35:38   
 * @author yuandong  
 * @version   
 * @since JDK 1.6
 */
@Repository
public class EducationRepository extends BaseDAO<EducationInfoEntity>{
	
	@Resource(name="templateChsi")
    private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}
    
    public void saveEducationInfo(EducationInfoEntity entity) throws Exception  {
    	entity.setCreateTime(DateUtil.getCurrentDate());
    	entity.setLastModifyTime(DateUtil.getCurrentDate());
		this.add(entity);
    }
    
    public void updateEducationInfo(EducationInfoEntity entity) throws Exception  {
    	entity.setLastModifyTime(DateUtil.getCurrentDate());
		this.modify(entity);
    }
    
    public EducationInfoEntity getEducationInfo(String userId,String certificateNo) throws Exception {
        String sql = "";
        String tableName = "t_education";
        sql = "select * from " + tableName + " where userId=? and certificateNo=?";
        EducationInfoEntity pojo = null;
        try{
         pojo = (EducationInfoEntity) queryOne(sql, new Object[] { userId,certificateNo }, new EducationInfoEntity());	
        }catch(EmptyResultDataAccessException e){
        	return null;
        }
        
        return pojo;
    }
    
    
}
